
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
    #region TicketReply Model -(by fangyifeng at 2009-11-22 22:48:29)

    /// <summary>
    /// TicketReply object'TicketReply'.
    /// </summary>
    public class TicketReply : System.IComparable
    {
        #region Member Variables

        protected Guid _id;
        protected string _contents;
        protected string _nickName;
        protected DateTime _replyTime;
        protected string _title;
        protected Ticket _ticket;

        protected static String _sortExpression = "Id";
        protected static SortDirection _sortDirection = SortDirection.Ascending;

        #endregion

        #region Constructors

        public TicketReply() { }

        public TicketReply(string contents, string nickName, DateTime replyTime, string title, Ticket ticket)
        {
            this._contents = contents;
            this._nickName = nickName;
            this._replyTime = replyTime;
            this._title = title;
            this._ticket = ticket;
        }

        #endregion

        #region Public Properties

        public virtual Guid Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public virtual string Contents
        {
            get { return _contents; }
            set
            {
               
                _contents = value;
            }
        }

        public virtual string NickName
        {
            get { return _nickName; }
            set
            {
                if (value != null && value.Length > 20)
                    throw new ArgumentOutOfRangeException("Invalid value for NickName", value, value.ToString());
                _nickName = value;
            }
        }

        public virtual DateTime ReplyTime
        {
            get { return _replyTime; }
            set { _replyTime = value; }
        }

        public virtual string Title
        {
            get { return _title; }
            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for Title", value, value.ToString());
                _title = value;
            }
        }

        public virtual Ticket Ticket
        {
            get { return _ticket; }
            set { _ticket = value; }
        }


        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
        #endregion

        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
            if (!(obj is TicketReply))
                throw new InvalidCastException("This object is not of type TicketReply");

            int relativeValue;
            switch (SortExpression)
            {
                case "Id":
                    relativeValue = this.Id.CompareTo(((TicketReply)obj).Id);
                    break;
                case "Contents":
                    relativeValue = this.Contents.CompareTo(((TicketReply)obj).Contents);
                    break;
                case "NickName":
                    relativeValue = this.NickName.CompareTo(((TicketReply)obj).NickName);
                    break;
                case "ReplyTime":
                    relativeValue = this.ReplyTime.CompareTo(((TicketReply)obj).ReplyTime);
                    break;
                case "Title":
                    relativeValue = (this.Title != null) ? this.Title.CompareTo(((TicketReply)obj).Title) : -1;
                    break;
                default:
                    goto case "Id";
            }
            if (TicketReply.SortDirection == SortDirection.Ascending)
                relativeValue *= -1;
            return relativeValue;
        }
        #endregion
    }

    #endregion
}
